import {app, Menu, Tray, dialog} from 'electron'
import {getMessageWindow} from "../message";
import {getMainWindow, getCreateWindow} from "../main";
import {getChatWindow} from "../chat";

class MyTray {

    constructor() {
        this.mainTray = null;
    }

    static createMainTray() {
        if (this.mainTray == null) {
            this.mainTray = new Tray(`${__static}/tray/Text_Edit_32.png`)
            let contextMenu = Menu.buildFromTemplate([
                {
                    id: '50',
                    icon: `${__static}/tray/Text_Edit_16.png`,
                    type: 'normal',
                    label: '创作',
                    click: MyTray.createArticle
                },
                {
                    id: '70',
                    icon: `${__static}/tray/Text_Edit_16.png`, type: 'normal', label: '即时通讯', click: MyTray.inChat
                },
                {
                    id: '80',
                    icon: `${__static}/tray/Text_Edit_16.png`, type: 'normal', label: '通知', click: MyTray.msg
                },
                {
                    id: '90',
                    icon: `${__static}/tray/Text_Edit_16.png`, type: 'normal', label: '进入系统', click: MyTray.toSystem
                },
                {
                    id: '100',
                    icon: `${__static}/tray/Text_Edit_16.png`, type: 'normal', label: '退出', click: MyTray.exitSystem
                }
            ])
            this.mainTray.setToolTip('Author 开始你的创作')
            this.mainTray.setContextMenu(contextMenu)
            this.mainTray.on('double-click', () => {
                MyTray.toSystem()
            })
        }
        return this.mainTray;
    }


    static msg() {
        dialog.showOpenDialog()
        dialog.showSaveDialog()
        dialog.showMessageBox({
            type:"question",
            title: "info",
            message: "info",
            buttons:["确定", "取消"]
        })
        dialog.showErrorBox("error", "error")
        getMessageWindow();
    }

    static toSystem() {
        getMainWindow();
    }

    static inChat() {
        getChatWindow()
    }

    static createArticle() {
        getCreateWindow()
    }

    static exitSystem() {
        app.quit()
    }
}

export default MyTray;